<template>
  <div>
    <router-link to="/" tag="div" class="header-abs"
                 v-show="showabs"
    ><span class="iconfont header-icon">&#xe624;</span></router-link>
    <div class="header-fixed" v-show="!showabs" :style="opacityStyle">
      <router-link to="/" tag="div"><span class="iconfont header-fixed-icon">&#xe624;</span></router-link>
      景点详情
    </div>
  </div>

</template>

<script>
  export default {
    name: "DetailHeader",
    data() {
      return {
        showabs: true,
        opacityStyle: {
          opacity: 0
        }
      }
    },
    methods: {
      handScroll() {
        const top = document.documentElement.scrollTop
        if (top > 60) {
          let opacity = top / 140
          opacity = opacity > 1 ? 1 : opacity
          this.opacityStyle = {opacity}
          this.showabs = false
        } else {
          this.showabs = true
        }
        // console.log(document.documentElement.scrollTop)
      }
    },
    activated() {
      window.addEventListener('scroll', this.handScroll)
    },
    deactivated() {
      window.removeEventListener('scroll', this.handScroll)
    }
  }
</script>

<style scoped>
  .header-abs {
    position: absolute;
    left: .2rem;
    top: .2rem;
    width: .8rem;
    height: .8rem;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.4);
    line-height: .8rem;
    text-align: center;
  }

  .header-icon {
    color: #ffffff;
  }

  .header-fixed {
    z-index: 3;
    position: fixed;
    overflow: hidden;
    height: .86rem;
    line-height: .86rem;
    width: 100%;
    text-align: center;
    color: #ffffff;
    top: 0;
    left: 0;
    right: 0;
    background-color: #25a4bb;
  }

  .header-fixed-icon {
    width: .86rem;
    color: #ffffff;
    text-align: center;
    font-size: 20px;
    position: absolute;
    top: 0;
    left: 0;
  }
</style>
